home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / util / prtfonts.10 / setup.h < prev   
C/C++ Source or Header  |  1990-03-04  |  4KB  |  135 lines

  1. #include <exec/types.h>
  2. #include <exec/exec.h>
  3. #include <intuition/intuition.h>
  4. #include <libraries/dos.h>
  5. #include <libraries/diskfont.h>
  6. #include <devices/printer.h>
  7.  
  8. struct IntuitionBase *IntuitionBase;
  9. struct GfxBase *GfxBase;
  10. struct DosBase *DosBase;
  11. struct DiskfontBase *DiskfontBase;
  12. struct Port *printerPort;
  13. struct TextFont *Topaz;
  14. struct TextAttr TopazAttr;
  15.  
  16. union printerIO
  17. {
  18.    struct IOStdReq ios;
  19.    struct IODRPReq iodrp;
  20.    struct IOPrtCmdReq iopc;
  21. };
  22.  
  23. union printerIO *printerMsg;
  24.  
  25.  
  26. #define MAX_X 960
  27. #define MAX_Y 720
  28. #define STARTINGROW 0
  29.  
  30. struct NewScreen NewScr = 
  31. {
  32.    0,0,640,200,1,0,1,HIRES,CUSTOMSCREEN,NULL,
  33.    "PrintFonts V1.10 (c)1989, 1990 by Dave Schreiber.  All Rights Reserved.",
  34.    NULL,NULL
  35. };
  36.  
  37. struct NewWindow NewWdw =
  38. {
  39.    0,10,640,190,-1,-1,NULL,SUPER_BITMAP|BORDERLESS|GIMMEZEROZERO,
  40.    NULL,NULL,NULL,NULL,NULL,0,0,0,0,CUSTOMSCREEN
  41. };
  42.  
  43.  
  44. struct Screen *Scr;
  45. struct Window *Wdw;
  46. struct BitMap BM;
  47.  
  48. void startup();
  49. void ConstructBitmap();
  50. void OpenPrinter();
  51. void closeup();
  52. void ExitProg();
  53.  
  54. void startup()        /*Open libraries, etc.*/
  55. {
  56.    if((IntuitionBase=(struct IntuitionBase *)OpenLibrary
  57.          ("intuition.library",0))==NULL)     /*IntuitionBase*/
  58.       ExitProg("Can't open intuitionbase!");
  59.    
  60.    if((GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0))==NULL)
  61.       ExitProg("Can't open GfxBase!");       /*GfxBase*/
  62.       
  63.    if((DosBase=(struct DosBase *)OpenLibrary("dos.library",0))==NULL)
  64.       ExitProg("Can't open DosBase!");       /*DosBase*/
  65.       
  66.    if((DiskfontBase=(struct DiskfontBase *)OpenLibrary("diskfont.library",
  67.          0))==NULL)                           /*DiskfontBase*/
  68.       ExitProg("Can't open DiskfontBase!");
  69.    
  70.    OpenPrinter(); /*Open the printer.device*/
  71.    Scr=(struct Screen *)OpenScreen(&NewScr);
  72.    if(Scr == NULL)
  73.       ExitProg("Couldn't open the screen!");
  74.    ScreenToBack(Scr); /*Push the brand new screen to the back (hide it)*/
  75.    NewWdw.Screen=(struct Screen *)Scr;
  76.    ConstructBitmap(&NewWdw,&BM);
  77.    Wdw=(struct Window *)OpenWindow(&NewWdw); /*Open the window*/
  78.    if(Wdw==NULL)
  79.    {
  80.       CloseScreen(Scr);
  81.       ExitProg("Couldn't open the window!");
  82.    }
  83.    else
  84.    {
  85.       SetRGB4(ViewPortAddress(Wdw),0,0xf,0xf,0xf);  /*White background*/
  86.       SetRGB4(ViewPortAddress(Wdw),1,0,0,0);        /*Black text*/
  87.    }
  88.    
  89. }
  90.    
  91. void ConstructBitmap(nw,bm) /*Setup the bitmap for the window*/
  92. struct NewWindow *nw;
  93. struct BitMap *bm;
  94. {
  95.    InitBitMap(bm,1,MAX_X,MAX_Y);    /*Initialize the superbitmap*/
  96.    if((bm->Planes[0]=(PLANEPTR)AllocRaster(MAX_X,MAX_Y))==NULL)
  97.       ExitProg("Couldn't allocate enough memory!");
  98.    nw->BitMap=(struct BitMap *)bm;     /*Link the BitMap into the Window*/   
  99. }
  100.  
  101. void OpenPrinter() /*Open the printer device*/
  102. {
  103.    printerPort=(struct Port *)CreatePort("my.print.port",0);
  104.    if(printerPort == NULL)
  105.       ExitProg("Couldn't access the printer!");
  106.    printerMsg=(union printerIO *)CreateExtIO(printerPort,
  107.          sizeof(union printerIO));
  108.    if(printerMsg==NULL)
  109.       ExitProg("Couldn't access the printer!");
  110.    if(OpenDevice("printer.device",0,printerMsg,0)!=NULL)
  111.       ExitProg("Couldn't access the printer!");
  112. }
  113.  
  114. void closeup()         /*Close libraries, etc.*/
  115. {
  116.    CloseFont(Topaz);
  117.    CloseDevice(printerMsg);
  118.    DeleteExtIO(printerMsg,sizeof(union printerIO));
  119.    DeletePort(printerPort);
  120.    CloseWindow(Wdw);
  121.    FreeRaster(BM.Planes[0],MAX_X,MAX_Y);
  122.    CloseScreen(Scr);
  123.    CloseLibrary(DiskfontBase);   /*Close diskfont.library*/
  124.    CloseLibrary(DosBase);         /*Close dos.library*/
  125.    CloseLibrary(GfxBase);         /*Close graphics.library*/
  126.    CloseLibrary(IntuitionBase);   /*Close intuition.library*/
  127. }
  128.  
  129. void ExitProg(err)        /*Error.  So print a message & terminate*/
  130. char *err;
  131. {
  132.    puts(err);  /*Print the error*/
  133.    exit(100);  /*and exit*/
  134. }
  135.